// 2025/4/7
// 牛牛冲钻五

#include <iostream>
using namespace std;

int main() {
    int T, n, k; cin >> T;
    while(T--)
    {
        cin >> n >> k;
        int score = 0;
        char ppre = 'L', pre = 'L', cur = 'L';
        while(n--)
        {
            ppre = pre;
            pre = cur;
            cin >> cur;
            if(ppre == 'W' && pre == 'W' && cur == 'W')
                score += k;
            else if(cur == 'W')
                score += 1;
            else
                score -= 1;
        }
        cout << score << endl;
    }
}
// 64 位输出请用 printf("%lld")